package cn.zl.rtsp.session;

import cn.zl.rtsp.udp.UDPSocket;
import io.netty.channel.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RTSPSession {

    protected static final Logger logger = LoggerFactory.getLogger(RTSPSession.class);

    /**
     * 会话ID
     */
    private String id;
    private boolean rtpTcp = false;  //RTPTCP标识

    /**
     * RTP/TCP网络连接
     */
    private Channel channel;
    private int rtpChannelId;  //RTP/TCP通信渠道标识
    private int rtcpChannelId;  //RTCP/TCP通信渠道标识

    /**
     * RTP/UDP网络连接
     */
    private int rtpClientPort;  //RTP/UDP客户端端口号
    private int rtcpClientPort;  //RTP/UDP客户端端口号
    private int rtpServerPort;  //RTP/UDP客户端端口号
    private int rtcpServerPort;  //RTP/UDP客户端端口号
    private UDPSocket rtpUdpSocket; //RTP/UDP服务端Socket
    private UDPSocket rtcpUdpSocket;//RTCP/UDP服务端Socket

    public void initUDPSocket() {
        rtpUdpSocket = new UDPSocket();
        if (!rtpUdpSocket.open(rtpServerPort)) {
            logger.info("启动RTP Socket服务失败");
        } else {
            logger.info("启动RTP Socket服务成功");
        }
        rtcpUdpSocket = new UDPSocket();
        if (!rtcpUdpSocket.open(rtcpServerPort)) {
            logger.info("启动RTCP Socket服务失败");
        } else {
            logger.info("启动RTCP Socket服务成功");
        }

    }

    public void id(String id) {
        this.id = id;
    }

    public void channel(Channel channel) {
        this.channel = channel;
    }

    public void rtpTcp(boolean rtpTcp) {
        this.rtpTcp = rtpTcp;
    }

    public void rtpClientPort(int rtpClientPort) {
        this.rtpClientPort = rtpClientPort;
    }

    public void rtcpClientPort(int rtcpClientPort) {
        this.rtcpClientPort = rtcpClientPort;
    }

    public void rtpServerPort(int rtpServerPort) {
        this.rtpServerPort = rtpServerPort;
    }

    public void rtcpServerPort(int rtcpServerPort) {
        this.rtcpServerPort = rtcpServerPort;
    }


    public String getId() {
        return id;
    }

    public boolean isRtpTcp() {
        return rtpTcp;
    }

    public int getRtpClientPort() {
        return rtpClientPort;
    }

    public int getRtcpClientPort() {
        return rtcpClientPort;
    }

    public int getRtpServerPort() {
        return rtpServerPort;
    }

    public int getRtcpServerPort() {
        return rtcpServerPort;
    }

    public UDPSocket getRtpUdpSocket() {
        return rtpUdpSocket;
    }

    public UDPSocket getRtcpUdpSocket() {
        return rtcpUdpSocket;
    }
}
